from typing import *


class Solution:

    def countServers(self, n: int, logs: List[List[int]], x: int,
                     queries: List[int]) -> List[int]:
        logs.sort(key=lambda a: a[1])
        d = DefaultDict(int)
        idx = [i for i in range(len(queries))]
        idx.sort(key=lambda i: queries[i])
        L = R = 0
        ans = [0] * len(queries)
        for i in range(len(queries)):
            t = queries[idx[i]]
            l, r = t - x, t
            while R < len(logs) and logs[R][1] <= r:
                d[logs[R][0]] += 1
                R += 1
            while L < len(logs) and logs[L][1] < l:
                d[logs[L][0]] -= 1
                if d[logs[L][0]] == 0:
                    d.pop(logs[L][0])
                L += 1
            ans[idx[i]] = n - len(d)
        return ans


so = Solution()
ans = so.countServers(n=3,
                      logs=[[1, 3], [2, 6], [1, 5]],
                      x=5,
                      queries=[10, 11])
print(ans)